﻿<UserControl x:Class="SynTorrent.TaskListControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.Resources>
        <!-- DataGrid style -->
        <Style x:Key="ColumnHeaderGripperStyle" TargetType="{x:Type Thumb}">
            <Setter Property="Width" Value="8"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Cursor" Value="SizeWE"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}" >
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Foreground" Value="Black"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="DataGridStyle1" TargetType="{x:Type DataGrid}">
            <Setter Property="ColumnHeaderStyle" Value="{DynamicResource ColumnHeaderStyle1}"/>
            <Setter Property="CellStyle" Value="{DynamicResource DataGridCellStyle}"/>
            <Setter Property="VerticalGridLinesBrush" Value="DarkGray"/>
            <Setter Property="HorizontalGridLinesBrush" Value="DarkGray"/>
            <Setter Property="Background" Value="DarkGray"/>
            <Setter Property="Foreground" Value="Black"/>
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Foreground" Value="Black"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <!-- DataGridColumnHeader style -->
        <Style x:Key="ColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Height" Value="30"/>
            <Setter Property="Background" Value="DimGray"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                        <Grid>
                            <Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" IsClickable="{TemplateBinding CanUserSort}" IsPressed="{TemplateBinding IsPressed}" IsHovered="{TemplateBinding IsMouseOver}" Padding="{TemplateBinding Padding}" SortDirection="{TemplateBinding SortDirection}" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter Grid.Column="0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="0,0,4,0"/>
                                    <Path x:Name="SortArrow"
            								Grid.Column="1"
            								HorizontalAlignment="Right" VerticalAlignment="Center"                                           
            								Width="8" Height="6" Margin="2,0,5,0"
            								Stretch="Fill" Opacity="0.5" Fill="White"
            								RenderTransformOrigin="0.5,0.4"
            								Visibility="Collapsed"
            								Data="M0,0 L1,0 0.5,1 z" />
                                </Grid>
                            </Themes:DataGridHeaderBorder>
                            <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{StaticResource ColumnHeaderGripperStyle}"/>
                            <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="SortDirection" Value="Ascending">
                                <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                                <Setter TargetName="SortArrow" Property="RenderTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="180" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="SortDirection" Value="Descending">
                                <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="ToolTip" Value="Click to sort"/>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!-- See http://elysium.codeplex.com/SourceControl/latest#2.0/Source%20code/Elysium/Themes/Scrolls/ScrollBar.xaml -->
        <Style TargetType="{x:Type ScrollBar}">
            <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource MiddleLightBrush}"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False"/>
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Style.Triggers>
                <Trigger Property="Orientation" Value="Horizontal">
                    <Setter Property="MinHeight" Value="6"/>
                    <Setter Property="Height" Value="12"/>
                    <Setter Property="MaxHeight" Value="20"/>
                    <Setter Property="Template" Value="{StaticResource HorizontalScrollBarTemplate}"/>
                </Trigger>
                <Trigger Property="Orientation" Value="Vertical">
                    <Setter Property="MinWidth" Value="6"/>
                    <Setter Property="Width" Value="12"/>
                    <Setter Property="MaxWidth" Value="20"/>
                    <Setter Property="Template" Value="{StaticResource VerticalScrollBarTemplate}"/>
                </Trigger>
            </Style.Triggers>
            
        </Style>
    </UserControl.Resources>
    
    <Grid>
        <DataGrid x:Name="TaskList" IsSynchronizedWithCurrentItem="True" 
                  Style="{DynamicResource DataGridStyle1}" 
                  AutoGeneratingColumn="TaskList_AutoGeneratingColumn" 
                  Grid.Column="2" 
                  BorderThickness="0" 
                  CanUserResizeRows="False" Background="#FF1E1E1E" 
                  >
            <DataGrid.RowStyle>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="Background">
                        <Setter.Value>
                            <SolidColorBrush Color="{Binding TaskStateColor}"/>
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataGrid.RowStyle>
        </DataGrid>
    </Grid>
</UserControl>
